using DG.Tweening;
using PP.Basic;
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace PP.PPPoker.Game.GJ25
{
    /// <summary>
    /// 点击音效
    /// </summary>
    public class ClickAudioPlayer : MonoBehaviour, IPointerClickHandler, IBeginDragHandler
    {
        private const string Tag = nameof(ClickAudioPlayer);

        private bool canPlayClickAudio = true;

        private string defaultAudioPath = AudioConfig.ButtonClick; // 默认音效路径


        [SerializeField, Header("音效(空為靜音)")] private AudioClip clickAudio;

        private void Awake()
        {
            Selectable sco = GetComponent<Selectable>();
            if (sco == null)
            {
                Debug.LogWarning($"{Tag}.no Selectable component! {gameObject.name}");
                // Debug.LogWarning("\n\n\n\n");
                return;
            }
        }

        private void OnDisable()
        {
        }


        // IBeginDragHandler
        public void OnBeginDrag(PointerEventData eventData)
        {
            // Debug.Log($"{Tag}.OnBeginDrag ...................");
            // 滑动时取消点击音效播放
            canPlayClickAudio = false;
        }


        // IPointerUpHandler
        public void OnPointerClick(PointerEventData eventData)
        {
            // Debug.Log($"{Tag}.OnPointerClick ...................");
            if (clickAudio != null && canPlayClickAudio)
            {
                // 点击音效独立于游戏音效
                Audio.Instance.PlayClick(clickAudio);
            }
            else
                canPlayClickAudio = true;
        }
    }
}
